<template>
  <div>
    <div id="head">
      <el-input placeholder="搜索用户名" v-model="input1" clearable> </el-input>
      <el-button type="primary" icon="el-icon-search">搜索</el-button>
      <el-button type="primary" style="float:right" @click="addperson" >+添加</el-button>
    </div>

    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"> </el-table-column>
      <el-table-column label="创建时间" width="120">
        <template slot-scope="scope">{{ scope.row.date }}</template>
      </el-table-column>
      <el-table-column label="id" >
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column label="昵称" >
        <template slot-scope="scope">{{ scope.row.nickName }}</template>
      </el-table-column>
      <el-table-column label="姓名" width="120">
        <template slot-scope="scope">{{ scope.row.name }}</template>
      </el-table-column>
      <el-table-column label="性别" width="120">
        <template slot-scope="scope">{{ scope.row.sex }}</template>
      </el-table-column>
      <el-table-column label="联系方式" width="120">
        <template slot-scope="scope">{{ scope.row.phone }}</template>
      </el-table-column>
      <el-table-column label="状态" width="120">
        <template slot-scope="scope">{{ scope.row.state}}</template>
      </el-table-column>
      <el-table-column
      prop="tag"
      label="标签"
      width="100">
      <template slot-scope="scope">
        <el-tag
          :type="scope.row.state === '启用' ? 'success' : 'primary'"
          disable-transitions>{{scope.row.state}}</el-tag>
      </template>
    </el-table-column>
      <el-table-column label="操作" width="220">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleNoUse(scope.$index, scope.row)"
            >禁用</el-button
          >
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :visible.sync="dialogFormVisible">
      <label for="题干："></label>
      <h3>{{ dialogdata.stem }}</h3>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogFormVisible2">
      <label for=""></label> 
      <h3>{{ dialogdata.stem }}</h3>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible2 = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>


<style lang="less" scoped>
.el-input {
  width: 20%;
  margin: 10px;
}
</style>

<script>
export default {
  data() {
    return {
      input1:'',
      input2:'',
      dialogFormVisible: false,
      dialogFormVisible2:false,
      dialogdata: {
        stem: "",
      },
      tableData: [
        {
          date: "2016-05-03",
          id:'001',
          nickName:'so_what?',
          name:'周雪有',
          sex:'女',
          phone:'15523025485',
          state:'启用'
        },
        {
          date: "2016-05-03",
          id:'002',
          nickName:'so_what?',
          name:'周雪有',
          sex:'女',
          phone:'15523025485',
          state:'启用'
        },
        {
          date: "2016-05-03",
          id:'003',
          nickName:'so_what?',
          name:'周雪有',
          sex:'女',
          phone:'15523025485',
          state:'启用'
        },
      ],
      multipleSelection: [],
    };
  },

  methods: {
    addperson(){
      this.dialogFormVisible2=true;
    },
    toggleSelection(rows) {
      if (rows) {
        rows.forEach((row) => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleNoUse(){
    },
    handleEdit(index, row) {
      this.dialogFormVisible = true;
      this.dialogdata.stem = b.stem;
    },
    handleDelete(index, row) {
      this.$confirm("将永久删除此试卷, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          this.tableData = this.filterArr2(this.tableData, row);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    filterArr2(data, row) {
      return data.filter((el) => {
        return el.id != row.id;
      });
    },
  },
};
</script>

